
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 10/07/2012 14:50:49
-- Generated from EDMX file: C:\Users\Ana\Desktop\ProjetoPET\ProjetoPET\ProjetoPET\Models\DBProjetoPet.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [ProjetoPet];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_AdminUsuario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Admin] DROP CONSTRAINT [FK_AdminUsuario];
GO
IF OBJECT_ID(N'[dbo].[FK_PermissaoTipoPermissao]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Permissao] DROP CONSTRAINT [FK_PermissaoTipoPermissao];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioHistorico]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Historico] DROP CONSTRAINT [FK_UsuarioHistorico];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioStatus]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Usuario] DROP CONSTRAINT [FK_UsuarioStatus];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioOrganizacao]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Usuario] DROP CONSTRAINT [FK_UsuarioOrganizacao];
GO
IF OBJECT_ID(N'[dbo].[FK_AdminTermoUtilizacao]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TermoUtilizacao] DROP CONSTRAINT [FK_AdminTermoUtilizacao];
GO
IF OBJECT_ID(N'[dbo].[FK_AdminFaq]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Faq] DROP CONSTRAINT [FK_AdminFaq];
GO
IF OBJECT_ID(N'[dbo].[FK_FaqCategoriaFaq]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Faq] DROP CONSTRAINT [FK_FaqCategoriaFaq];
GO
IF OBJECT_ID(N'[dbo].[FK_TermoUtilizacaoTipoTermoUtilizacao]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TermoUtilizacao] DROP CONSTRAINT [FK_TermoUtilizacaoTipoTermoUtilizacao];
GO
IF OBJECT_ID(N'[dbo].[FK_HistoricoAcaoHistorico]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Historico] DROP CONSTRAINT [FK_HistoricoAcaoHistorico];
GO
IF OBJECT_ID(N'[dbo].[FK_FotoStatus]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Foto] DROP CONSTRAINT [FK_FotoStatus];
GO
IF OBJECT_ID(N'[dbo].[FK_AnimalFoto]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Foto] DROP CONSTRAINT [FK_AnimalFoto];
GO
IF OBJECT_ID(N'[dbo].[FK_AnimalRaca]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Animal] DROP CONSTRAINT [FK_AnimalRaca];
GO
IF OBJECT_ID(N'[dbo].[FK_AnimalStatus]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Animal] DROP CONSTRAINT [FK_AnimalStatus];
GO
IF OBJECT_ID(N'[dbo].[FK_AnimalOrigem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Animal] DROP CONSTRAINT [FK_AnimalOrigem];
GO
IF OBJECT_ID(N'[dbo].[FK_AnimalCidade]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Animal] DROP CONSTRAINT [FK_AnimalCidade];
GO
IF OBJECT_ID(N'[dbo].[FK_AnimalTamanho]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Animal] DROP CONSTRAINT [FK_AnimalTamanho];
GO
IF OBJECT_ID(N'[dbo].[FK_AnimalCor_Animal]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AnimalCor] DROP CONSTRAINT [FK_AnimalCor_Animal];
GO
IF OBJECT_ID(N'[dbo].[FK_AnimalCor_Cor]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AnimalCor] DROP CONSTRAINT [FK_AnimalCor_Cor];
GO
IF OBJECT_ID(N'[dbo].[FK_AnimalTemperamento]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Animal] DROP CONSTRAINT [FK_AnimalTemperamento];
GO
IF OBJECT_ID(N'[dbo].[FK_RacaTipoAnimal]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Raca] DROP CONSTRAINT [FK_RacaTipoAnimal];
GO
IF OBJECT_ID(N'[dbo].[FK_CidadeEstado]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Cidade] DROP CONSTRAINT [FK_CidadeEstado];
GO
IF OBJECT_ID(N'[dbo].[FK_ContatoTipoContato]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Contato] DROP CONSTRAINT [FK_ContatoTipoContato];
GO
IF OBJECT_ID(N'[dbo].[FK_DenunciaMotivoDenuncia]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Denuncia] DROP CONSTRAINT [FK_DenunciaMotivoDenuncia];
GO
IF OBJECT_ID(N'[dbo].[FK_NotificacaoTipoNotificacao]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Notificacao] DROP CONSTRAINT [FK_NotificacaoTipoNotificacao];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioNotificacao]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Notificacao] DROP CONSTRAINT [FK_UsuarioNotificacao];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioChaveAcesso]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ChaveAcesso] DROP CONSTRAINT [FK_UsuarioChaveAcesso];
GO
IF OBJECT_ID(N'[dbo].[FK_ChaveAcessoTipoChave]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ChaveAcesso] DROP CONSTRAINT [FK_ChaveAcessoTipoChave];
GO
IF OBJECT_ID(N'[dbo].[FK_TipoNotificacaoMeioNotificacao_TipoNotificacao]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TipoNotificacaoMeioNotificacao] DROP CONSTRAINT [FK_TipoNotificacaoMeioNotificacao_TipoNotificacao];
GO
IF OBJECT_ID(N'[dbo].[FK_TipoNotificacaoMeioNotificacao_MeioNotificacao]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TipoNotificacaoMeioNotificacao] DROP CONSTRAINT [FK_TipoNotificacaoMeioNotificacao_MeioNotificacao];
GO
IF OBJECT_ID(N'[dbo].[FK_AnimalDoacao]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Doacao] DROP CONSTRAINT [FK_AnimalDoacao];
GO
IF OBJECT_ID(N'[dbo].[FK_DoacaoCandidato]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Candidato] DROP CONSTRAINT [FK_DoacaoCandidato];
GO
IF OBJECT_ID(N'[dbo].[FK_FormularioContato]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Contato] DROP CONSTRAINT [FK_FormularioContato];
GO
IF OBJECT_ID(N'[dbo].[FK_FormularioTipoResidencia]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Formulario] DROP CONSTRAINT [FK_FormularioTipoResidencia];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioFormulario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Formulario] DROP CONSTRAINT [FK_UsuarioFormulario];
GO
IF OBJECT_ID(N'[dbo].[FK_FormularioStatus]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Formulario] DROP CONSTRAINT [FK_FormularioStatus];
GO
IF OBJECT_ID(N'[dbo].[FK_FormularioCidade]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Formulario] DROP CONSTRAINT [FK_FormularioCidade];
GO
IF OBJECT_ID(N'[dbo].[FK_CandidatoFormulario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Candidato] DROP CONSTRAINT [FK_CandidatoFormulario];
GO
IF OBJECT_ID(N'[dbo].[FK_CandidatoStatus]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Candidato] DROP CONSTRAINT [FK_CandidatoStatus];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioRelacaoUsuarioAnimal]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RelacaoUsuarioAnimal] DROP CONSTRAINT [FK_UsuarioRelacaoUsuarioAnimal];
GO
IF OBJECT_ID(N'[dbo].[FK_AnimalRelacaoUsuarioAnimal]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RelacaoUsuarioAnimal] DROP CONSTRAINT [FK_AnimalRelacaoUsuarioAnimal];
GO
IF OBJECT_ID(N'[dbo].[FK_RelacaoUsuarioAnimalStatus]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RelacaoUsuarioAnimal] DROP CONSTRAINT [FK_RelacaoUsuarioAnimalStatus];
GO
IF OBJECT_ID(N'[dbo].[FK_AdminDenuncia]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Denuncia] DROP CONSTRAINT [FK_AdminDenuncia];
GO
IF OBJECT_ID(N'[dbo].[FK_DenunciaTicket]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Denuncia] DROP CONSTRAINT [FK_DenunciaTicket];
GO
IF OBJECT_ID(N'[dbo].[FK_TicketTipoTicket]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Ticket] DROP CONSTRAINT [FK_TicketTipoTicket];
GO
IF OBJECT_ID(N'[dbo].[FK_ObjetoTipoObjeto]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Objeto] DROP CONSTRAINT [FK_ObjetoTipoObjeto];
GO
IF OBJECT_ID(N'[dbo].[FK_ObjetoMotivoDenuncia]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MotivoDenuncia] DROP CONSTRAINT [FK_ObjetoMotivoDenuncia];
GO
IF OBJECT_ID(N'[dbo].[FK_TipoTicketObjeto]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TipoTicket] DROP CONSTRAINT [FK_TipoTicketObjeto];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioApreciar]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Apreciar] DROP CONSTRAINT [FK_UsuarioApreciar];
GO
IF OBJECT_ID(N'[dbo].[FK_ApreciarObjeto]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Apreciar] DROP CONSTRAINT [FK_ApreciarObjeto];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioSeguir]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Seguir] DROP CONSTRAINT [FK_UsuarioSeguir];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioMensagemDestinatario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Mensagem] DROP CONSTRAINT [FK_UsuarioMensagemDestinatario];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuarioMensagemRemetente]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Mensagem] DROP CONSTRAINT [FK_UsuarioMensagemRemetente];
GO
IF OBJECT_ID(N'[dbo].[FK_DoacaoMensagem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Mensagem] DROP CONSTRAINT [FK_DoacaoMensagem];
GO
IF OBJECT_ID(N'[dbo].[FK_DoacaoUsuario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Doacao] DROP CONSTRAINT [FK_DoacaoUsuario];
GO
IF OBJECT_ID(N'[dbo].[FK_DenunciaStatus]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Denuncia] DROP CONSTRAINT [FK_DenunciaStatus];
GO
IF OBJECT_ID(N'[dbo].[FK_AdminStatus]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Admin] DROP CONSTRAINT [FK_AdminStatus];
GO
IF OBJECT_ID(N'[dbo].[FK_TicketAdmin]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Ticket] DROP CONSTRAINT [FK_TicketAdmin];
GO
IF OBJECT_ID(N'[dbo].[FK_SeguirAnimal]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Seguir] DROP CONSTRAINT [FK_SeguirAnimal];
GO
IF OBJECT_ID(N'[dbo].[FK_AcaoHistoricoObjeto]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AcaoHistorico] DROP CONSTRAINT [FK_AcaoHistoricoObjeto];
GO
IF OBJECT_ID(N'[dbo].[FK_FormularioEstadoCivil]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Formulario] DROP CONSTRAINT [FK_FormularioEstadoCivil];
GO
IF OBJECT_ID(N'[dbo].[FK_AdminPermissao]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Permissao] DROP CONSTRAINT [FK_AdminPermissao];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Usuario]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Usuario];
GO
IF OBJECT_ID(N'[dbo].[Admin]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Admin];
GO
IF OBJECT_ID(N'[dbo].[Permissao]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Permissao];
GO
IF OBJECT_ID(N'[dbo].[Denuncia]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Denuncia];
GO
IF OBJECT_ID(N'[dbo].[Faq]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Faq];
GO
IF OBJECT_ID(N'[dbo].[TermoUtilizacao]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TermoUtilizacao];
GO
IF OBJECT_ID(N'[dbo].[Ticket]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Ticket];
GO
IF OBJECT_ID(N'[dbo].[Historico]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Historico];
GO
IF OBJECT_ID(N'[dbo].[AcaoHistorico]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AcaoHistorico];
GO
IF OBJECT_ID(N'[dbo].[Organizacao]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Organizacao];
GO
IF OBJECT_ID(N'[dbo].[Mensagem]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Mensagem];
GO
IF OBJECT_ID(N'[dbo].[ChaveAcesso]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ChaveAcesso];
GO
IF OBJECT_ID(N'[dbo].[Notificacao]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Notificacao];
GO
IF OBJECT_ID(N'[dbo].[Status]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Status];
GO
IF OBJECT_ID(N'[dbo].[Animal]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Animal];
GO
IF OBJECT_ID(N'[dbo].[Doacao]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Doacao];
GO
IF OBJECT_ID(N'[dbo].[TipoAnimal]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TipoAnimal];
GO
IF OBJECT_ID(N'[dbo].[Raca]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Raca];
GO
IF OBJECT_ID(N'[dbo].[Origem]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Origem];
GO
IF OBJECT_ID(N'[dbo].[Cidade]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Cidade];
GO
IF OBJECT_ID(N'[dbo].[Cor]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Cor];
GO
IF OBJECT_ID(N'[dbo].[Temperamento]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Temperamento];
GO
IF OBJECT_ID(N'[dbo].[Tamanho]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tamanho];
GO
IF OBJECT_ID(N'[dbo].[Foto]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Foto];
GO
IF OBJECT_ID(N'[dbo].[Seguir]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Seguir];
GO
IF OBJECT_ID(N'[dbo].[Apreciar]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Apreciar];
GO
IF OBJECT_ID(N'[dbo].[Objeto]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Objeto];
GO
IF OBJECT_ID(N'[dbo].[TipoNotificacao]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TipoNotificacao];
GO
IF OBJECT_ID(N'[dbo].[MeioNotificacao]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MeioNotificacao];
GO
IF OBJECT_ID(N'[dbo].[TipoChave]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TipoChave];
GO
IF OBJECT_ID(N'[dbo].[MotivoDenuncia]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MotivoDenuncia];
GO
IF OBJECT_ID(N'[dbo].[TipoTicket]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TipoTicket];
GO
IF OBJECT_ID(N'[dbo].[Candidato]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Candidato];
GO
IF OBJECT_ID(N'[dbo].[Formulario]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Formulario];
GO
IF OBJECT_ID(N'[dbo].[Contato]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Contato];
GO
IF OBJECT_ID(N'[dbo].[TipoContato]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TipoContato];
GO
IF OBJECT_ID(N'[dbo].[Estado]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Estado];
GO
IF OBJECT_ID(N'[dbo].[TipoObjeto]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TipoObjeto];
GO
IF OBJECT_ID(N'[dbo].[TipoPermissao]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TipoPermissao];
GO
IF OBJECT_ID(N'[dbo].[TipoTermoUtilizacao]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TipoTermoUtilizacao];
GO
IF OBJECT_ID(N'[dbo].[CategoriaFaq]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CategoriaFaq];
GO
IF OBJECT_ID(N'[dbo].[TipoResidencia]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TipoResidencia];
GO
IF OBJECT_ID(N'[dbo].[EstadoCivil]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EstadoCivil];
GO
IF OBJECT_ID(N'[dbo].[RelacaoUsuarioAnimal]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RelacaoUsuarioAnimal];
GO
IF OBJECT_ID(N'[dbo].[AnimalCor]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AnimalCor];
GO
IF OBJECT_ID(N'[dbo].[TipoNotificacaoMeioNotificacao]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TipoNotificacaoMeioNotificacao];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Usuario'
CREATE TABLE [dbo].[Usuario] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(200)  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Senha] nvarchar(max)  NOT NULL,
    [Apelido] nvarchar(max)  NOT NULL,
    [StatusId] int  NOT NULL,
    [Organizacao_Id] int  NOT NULL
);
GO

-- Creating table 'Admin'
CREATE TABLE [dbo].[Admin] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Ativo] bit  NOT NULL,
    [StatusId] int  NOT NULL,
    [Usuario_Id] int  NOT NULL
);
GO

-- Creating table 'Permissao'
CREATE TABLE [dbo].[Permissao] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Valor] bit  NOT NULL,
    [AdminId] int  NOT NULL,
    [AdminId1] int  NOT NULL,
    [TipoPermissao_Id] int  NOT NULL
);
GO

-- Creating table 'Denuncia'
CREATE TABLE [dbo].[Denuncia] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Descricao] nvarchar(max)  NOT NULL,
    [idReferencia] int  NOT NULL,
    [DataCriacao] datetime  NOT NULL,
    [MotivoDenunciaId] int  NOT NULL,
    [AdminId] int  NOT NULL,
    [StatusId] int  NOT NULL,
    [Ticket_Id] int  NOT NULL
);
GO

-- Creating table 'Faq'
CREATE TABLE [dbo].[Faq] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Pergunta] nvarchar(max)  NOT NULL,
    [Resposta] nvarchar(max)  NOT NULL,
    [AdminId] int  NOT NULL,
    [CategoriaFaqId] int  NOT NULL
);
GO

-- Creating table 'TermoUtilizacao'
CREATE TABLE [dbo].[TermoUtilizacao] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Texto] nvarchar(max)  NOT NULL,
    [DataInclusao] datetime  NOT NULL,
    [DataVigencia] datetime  NOT NULL,
    [AdminId] int  NOT NULL,
    [TipoTermoUtilizacaoId] int  NOT NULL
);
GO

-- Creating table 'Ticket'
CREATE TABLE [dbo].[Ticket] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [DataEvento] datetime  NOT NULL,
    [Descricao] nvarchar(max)  NOT NULL,
    [idReferencia] int  NOT NULL,
    [TipoTicketId] int  NOT NULL,
    [Admin_Id] int  NOT NULL
);
GO

-- Creating table 'Historico'
CREATE TABLE [dbo].[Historico] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Data] datetime  NOT NULL,
    [Ativo] bit  NOT NULL,
    [Titulo] nvarchar(max)  NOT NULL,
    [Conteudo] nvarchar(max)  NOT NULL,
    [UsuarioId] int  NOT NULL,
    [AcaoHistoricoId] int  NOT NULL
);
GO

-- Creating table 'AcaoHistorico'
CREATE TABLE [dbo].[AcaoHistorico] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [idReferencia] int  NOT NULL,
    [Ativo] bit  NOT NULL,
    [ObjetoId] int  NOT NULL
);
GO

-- Creating table 'Organizacao'
CREATE TABLE [dbo].[Organizacao] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Cnpj] nvarchar(18)  NOT NULL,
    [UrlIcone] nvarchar(max)  NULL,
    [Descricao] nvarchar(max)  NULL,
    [UrlSite] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Mensagem'
CREATE TABLE [dbo].[Mensagem] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Texto] nvarchar(max)  NOT NULL,
    [DataLeitura] datetime  NOT NULL,
    [DataEnvio] datetime  NOT NULL,
    [UsuarioIdRemetente] int  NOT NULL,
    [UsuarioIdDestinatario] int  NOT NULL,
    [DoacaoId] int  NOT NULL
);
GO

-- Creating table 'ChaveAcesso'
CREATE TABLE [dbo].[ChaveAcesso] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Valor] nvarchar(max)  NOT NULL,
    [Ativo] bit  NOT NULL,
    [UsuarioId] int  NOT NULL,
    [Expira] datetime  NOT NULL,
    [TipoChave_Id] int  NOT NULL
);
GO

-- Creating table 'Notificacao'
CREATE TABLE [dbo].[Notificacao] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Titulo] nvarchar(max)  NOT NULL,
    [Conteudo] nvarchar(max)  NOT NULL,
    [Lido] bit  NOT NULL,
    [Url] nvarchar(max)  NOT NULL,
    [TipoNotificacaoId] int  NOT NULL,
    [UsuarioId] int  NOT NULL
);
GO

-- Creating table 'Status'
CREATE TABLE [dbo].[Status] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Titulo] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Animal'
CREATE TABLE [dbo].[Animal] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(200)  NOT NULL,
    [DataNascimento] datetime  NULL,
    [Vacinado] bit  NULL,
    [Sexo] bit  NULL,
    [RacaId] int  NOT NULL,
    [StatusId] int  NOT NULL,
    [OrigemId] int  NOT NULL,
    [CidadeId] int  NOT NULL,
    [TamanhoId] int  NOT NULL,
    [TemperamentoId] int  NOT NULL,
    [IdadeAproximada] bit  NULL
);
GO

-- Creating table 'Doacao'
CREATE TABLE [dbo].[Doacao] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [DataInicio] datetime  NOT NULL,
    [DataFim] datetime  NOT NULL,
    [AnimalId] int  NOT NULL,
    [UsuarioId] int  NOT NULL
);
GO

-- Creating table 'TipoAnimal'
CREATE TABLE [dbo].[TipoAnimal] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Titulo] nvarchar(max)  NOT NULL,
    [Icone] nvarchar(256)  NULL
);
GO

-- Creating table 'Raca'
CREATE TABLE [dbo].[Raca] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Titulo] nvarchar(max)  NOT NULL,
    [Icone] nvarchar(256)  NULL,
    [TipoAnimalId] int  NOT NULL
);
GO

-- Creating table 'Origem'
CREATE TABLE [dbo].[Origem] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Titulo] nvarchar(max)  NOT NULL,
    [Adotavel] bit  NOT NULL,
    [Icone] nvarchar(256)  NULL
);
GO

-- Creating table 'Cidade'
CREATE TABLE [dbo].[Cidade] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(max)  NOT NULL,
    [Ativo] bit  NOT NULL,
    [EstadoId] int  NOT NULL
);
GO

-- Creating table 'Cor'
CREATE TABLE [dbo].[Cor] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Hex] nvarchar(7)  NOT NULL,
    [Nome] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Temperamento'
CREATE TABLE [dbo].[Temperamento] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Titulo] nvarchar(max)  NOT NULL,
    [Icone] nvarchar(256)  NULL
);
GO

-- Creating table 'Tamanho'
CREATE TABLE [dbo].[Tamanho] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Titulo] nvarchar(max)  NOT NULL,
    [Icone] nvarchar(256)  NULL
);
GO

-- Creating table 'Foto'
CREATE TABLE [dbo].[Foto] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Capa] bit  NOT NULL,
    [Url] nvarchar(256)  NOT NULL,
    [Uploadless] bit  NOT NULL,
    [StatusId] int  NOT NULL,
    [AnimalId] int  NOT NULL
);
GO

-- Creating table 'Seguir'
CREATE TABLE [dbo].[Seguir] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Data] datetime  NOT NULL,
    [Ativo] bit  NOT NULL,
    [UsuarioId] int  NOT NULL,
    [AnimalId] int  NOT NULL
);
GO

-- Creating table 'Apreciar'
CREATE TABLE [dbo].[Apreciar] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Data] datetime  NOT NULL,
    [Ativo] bit  NOT NULL,
    [UsuarioId] int  NOT NULL,
    [ObjetoId] int  NOT NULL,
    [idReferencia] int  NOT NULL
);
GO

-- Creating table 'Objeto'
CREATE TABLE [dbo].[Objeto] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(max)  NOT NULL,
    [TipoObjetoId] int  NOT NULL
);
GO

-- Creating table 'TipoNotificacao'
CREATE TABLE [dbo].[TipoNotificacao] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Titulo] nvarchar(max)  NOT NULL,
    [Modelo] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'MeioNotificacao'
CREATE TABLE [dbo].[MeioNotificacao] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Titulo] nvarchar(max)  NOT NULL,
    [Url] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'TipoChave'
CREATE TABLE [dbo].[TipoChave] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Titulo] nvarchar(max)  NOT NULL,
    [UrlAutenticacao] nvarchar(max)  NOT NULL,
    [Ativo] bit  NOT NULL,
    [UrlTermo] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'MotivoDenuncia'
CREATE TABLE [dbo].[MotivoDenuncia] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Titulo] nvarchar(max)  NOT NULL,
    [ObjetoId] int  NOT NULL
);
GO

-- Creating table 'TipoTicket'
CREATE TABLE [dbo].[TipoTicket] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Titulo] nvarchar(max)  NOT NULL,
    [ObjetoId] int  NOT NULL
);
GO

-- Creating table 'Candidato'
CREATE TABLE [dbo].[Candidato] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [DataInscricao] datetime  NOT NULL,
    [Prioridade] int  NOT NULL,
    [DoacaoId] int  NOT NULL,
    [FormularioId] int  NOT NULL,
    [Status_Id] int  NOT NULL
);
GO

-- Creating table 'Formulario'
CREATE TABLE [dbo].[Formulario] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Descricao] nvarchar(max)  NULL,
    [Sexo] bit  NULL,
    [DataNascimento] datetime  NULL,
    [Filhos] int  NULL,
    [RendaMedia] int  NULL,
    [TipoResidenciaId] int  NOT NULL,
    [UsuarioId] int  NOT NULL,
    [CidadeId] int  NOT NULL,
    [EstadoCivilId] int  NOT NULL,
    [Status_Id] int  NOT NULL
);
GO

-- Creating table 'Contato'
CREATE TABLE [dbo].[Contato] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Valor] nvarchar(max)  NOT NULL,
    [Prefixo] nvarchar(max)  NOT NULL,
    [Ativo] bit  NOT NULL,
    [TipoContatoId] int  NOT NULL,
    [FormularioId] int  NOT NULL
);
GO

-- Creating table 'TipoContato'
CREATE TABLE [dbo].[TipoContato] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Titulo] nvarchar(max)  NOT NULL,
    [Ativo] bit  NOT NULL
);
GO

-- Creating table 'Estado'
CREATE TABLE [dbo].[Estado] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Sigla] nvarchar(max)  NOT NULL,
    [Nome] nvarchar(max)  NOT NULL,
    [Ativo] bit  NOT NULL
);
GO

-- Creating table 'TipoObjeto'
CREATE TABLE [dbo].[TipoObjeto] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Titulo] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'TipoPermissao'
CREATE TABLE [dbo].[TipoPermissao] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Titulo] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'TipoTermoUtilizacao'
CREATE TABLE [dbo].[TipoTermoUtilizacao] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Titulo] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'CategoriaFaq'
CREATE TABLE [dbo].[CategoriaFaq] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Titulo] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'TipoResidencia'
CREATE TABLE [dbo].[TipoResidencia] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Titulo] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'EstadoCivil'
CREATE TABLE [dbo].[EstadoCivil] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Titulo] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'RelacaoUsuarioAnimal'
CREATE TABLE [dbo].[RelacaoUsuarioAnimal] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [DataCriacao] datetime  NOT NULL,
    [DataAlteracao] datetime  NOT NULL,
    [UsuarioId] int  NOT NULL,
    [AnimalId] int  NOT NULL,
    [StatusId] int  NOT NULL
);
GO

-- Creating table 'AnimalCor'
CREATE TABLE [dbo].[AnimalCor] (
    [AnimalCor_Cor_Id] int  NOT NULL,
    [Cor_Id] int  NOT NULL
);
GO

-- Creating table 'TipoNotificacaoMeioNotificacao'
CREATE TABLE [dbo].[TipoNotificacaoMeioNotificacao] (
    [TipoNotificacao_Id] int  NOT NULL,
    [MeioNotificacao_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Usuario'
ALTER TABLE [dbo].[Usuario]
ADD CONSTRAINT [PK_Usuario]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Admin'
ALTER TABLE [dbo].[Admin]
ADD CONSTRAINT [PK_Admin]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Permissao'
ALTER TABLE [dbo].[Permissao]
ADD CONSTRAINT [PK_Permissao]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Denuncia'
ALTER TABLE [dbo].[Denuncia]
ADD CONSTRAINT [PK_Denuncia]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Faq'
ALTER TABLE [dbo].[Faq]
ADD CONSTRAINT [PK_Faq]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TermoUtilizacao'
ALTER TABLE [dbo].[TermoUtilizacao]
ADD CONSTRAINT [PK_TermoUtilizacao]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Ticket'
ALTER TABLE [dbo].[Ticket]
ADD CONSTRAINT [PK_Ticket]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Historico'
ALTER TABLE [dbo].[Historico]
ADD CONSTRAINT [PK_Historico]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'AcaoHistorico'
ALTER TABLE [dbo].[AcaoHistorico]
ADD CONSTRAINT [PK_AcaoHistorico]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Organizacao'
ALTER TABLE [dbo].[Organizacao]
ADD CONSTRAINT [PK_Organizacao]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Mensagem'
ALTER TABLE [dbo].[Mensagem]
ADD CONSTRAINT [PK_Mensagem]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ChaveAcesso'
ALTER TABLE [dbo].[ChaveAcesso]
ADD CONSTRAINT [PK_ChaveAcesso]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Notificacao'
ALTER TABLE [dbo].[Notificacao]
ADD CONSTRAINT [PK_Notificacao]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Status'
ALTER TABLE [dbo].[Status]
ADD CONSTRAINT [PK_Status]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Animal'
ALTER TABLE [dbo].[Animal]
ADD CONSTRAINT [PK_Animal]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Doacao'
ALTER TABLE [dbo].[Doacao]
ADD CONSTRAINT [PK_Doacao]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TipoAnimal'
ALTER TABLE [dbo].[TipoAnimal]
ADD CONSTRAINT [PK_TipoAnimal]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Raca'
ALTER TABLE [dbo].[Raca]
ADD CONSTRAINT [PK_Raca]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Origem'
ALTER TABLE [dbo].[Origem]
ADD CONSTRAINT [PK_Origem]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Cidade'
ALTER TABLE [dbo].[Cidade]
ADD CONSTRAINT [PK_Cidade]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Cor'
ALTER TABLE [dbo].[Cor]
ADD CONSTRAINT [PK_Cor]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Temperamento'
ALTER TABLE [dbo].[Temperamento]
ADD CONSTRAINT [PK_Temperamento]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Tamanho'
ALTER TABLE [dbo].[Tamanho]
ADD CONSTRAINT [PK_Tamanho]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Foto'
ALTER TABLE [dbo].[Foto]
ADD CONSTRAINT [PK_Foto]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Seguir'
ALTER TABLE [dbo].[Seguir]
ADD CONSTRAINT [PK_Seguir]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Apreciar'
ALTER TABLE [dbo].[Apreciar]
ADD CONSTRAINT [PK_Apreciar]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Objeto'
ALTER TABLE [dbo].[Objeto]
ADD CONSTRAINT [PK_Objeto]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TipoNotificacao'
ALTER TABLE [dbo].[TipoNotificacao]
ADD CONSTRAINT [PK_TipoNotificacao]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'MeioNotificacao'
ALTER TABLE [dbo].[MeioNotificacao]
ADD CONSTRAINT [PK_MeioNotificacao]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TipoChave'
ALTER TABLE [dbo].[TipoChave]
ADD CONSTRAINT [PK_TipoChave]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'MotivoDenuncia'
ALTER TABLE [dbo].[MotivoDenuncia]
ADD CONSTRAINT [PK_MotivoDenuncia]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TipoTicket'
ALTER TABLE [dbo].[TipoTicket]
ADD CONSTRAINT [PK_TipoTicket]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Candidato'
ALTER TABLE [dbo].[Candidato]
ADD CONSTRAINT [PK_Candidato]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Formulario'
ALTER TABLE [dbo].[Formulario]
ADD CONSTRAINT [PK_Formulario]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Contato'
ALTER TABLE [dbo].[Contato]
ADD CONSTRAINT [PK_Contato]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TipoContato'
ALTER TABLE [dbo].[TipoContato]
ADD CONSTRAINT [PK_TipoContato]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Estado'
ALTER TABLE [dbo].[Estado]
ADD CONSTRAINT [PK_Estado]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TipoObjeto'
ALTER TABLE [dbo].[TipoObjeto]
ADD CONSTRAINT [PK_TipoObjeto]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TipoPermissao'
ALTER TABLE [dbo].[TipoPermissao]
ADD CONSTRAINT [PK_TipoPermissao]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TipoTermoUtilizacao'
ALTER TABLE [dbo].[TipoTermoUtilizacao]
ADD CONSTRAINT [PK_TipoTermoUtilizacao]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CategoriaFaq'
ALTER TABLE [dbo].[CategoriaFaq]
ADD CONSTRAINT [PK_CategoriaFaq]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TipoResidencia'
ALTER TABLE [dbo].[TipoResidencia]
ADD CONSTRAINT [PK_TipoResidencia]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EstadoCivil'
ALTER TABLE [dbo].[EstadoCivil]
ADD CONSTRAINT [PK_EstadoCivil]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'RelacaoUsuarioAnimal'
ALTER TABLE [dbo].[RelacaoUsuarioAnimal]
ADD CONSTRAINT [PK_RelacaoUsuarioAnimal]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [AnimalCor_Cor_Id], [Cor_Id] in table 'AnimalCor'
ALTER TABLE [dbo].[AnimalCor]
ADD CONSTRAINT [PK_AnimalCor]
    PRIMARY KEY NONCLUSTERED ([AnimalCor_Cor_Id], [Cor_Id] ASC);
GO

-- Creating primary key on [TipoNotificacao_Id], [MeioNotificacao_Id] in table 'TipoNotificacaoMeioNotificacao'
ALTER TABLE [dbo].[TipoNotificacaoMeioNotificacao]
ADD CONSTRAINT [PK_TipoNotificacaoMeioNotificacao]
    PRIMARY KEY NONCLUSTERED ([TipoNotificacao_Id], [MeioNotificacao_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Usuario_Id] in table 'Admin'
ALTER TABLE [dbo].[Admin]
ADD CONSTRAINT [FK_AdminUsuario]
    FOREIGN KEY ([Usuario_Id])
    REFERENCES [dbo].[Usuario]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AdminUsuario'
CREATE INDEX [IX_FK_AdminUsuario]
ON [dbo].[Admin]
    ([Usuario_Id]);
GO

-- Creating foreign key on [TipoPermissao_Id] in table 'Permissao'
ALTER TABLE [dbo].[Permissao]
ADD CONSTRAINT [FK_PermissaoTipoPermissao]
    FOREIGN KEY ([TipoPermissao_Id])
    REFERENCES [dbo].[TipoPermissao]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PermissaoTipoPermissao'
CREATE INDEX [IX_FK_PermissaoTipoPermissao]
ON [dbo].[Permissao]
    ([TipoPermissao_Id]);
GO

-- Creating foreign key on [UsuarioId] in table 'Historico'
ALTER TABLE [dbo].[Historico]
ADD CONSTRAINT [FK_UsuarioHistorico]
    FOREIGN KEY ([UsuarioId])
    REFERENCES [dbo].[Usuario]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuarioHistorico'
CREATE INDEX [IX_FK_UsuarioHistorico]
ON [dbo].[Historico]
    ([UsuarioId]);
GO

-- Creating foreign key on [StatusId] in table 'Usuario'
ALTER TABLE [dbo].[Usuario]
ADD CONSTRAINT [FK_UsuarioStatus]
    FOREIGN KEY ([StatusId])
    REFERENCES [dbo].[Status]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuarioStatus'
CREATE INDEX [IX_FK_UsuarioStatus]
ON [dbo].[Usuario]
    ([StatusId]);
GO

-- Creating foreign key on [Organizacao_Id] in table 'Usuario'
ALTER TABLE [dbo].[Usuario]
ADD CONSTRAINT [FK_UsuarioOrganizacao]
    FOREIGN KEY ([Organizacao_Id])
    REFERENCES [dbo].[Organizacao]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuarioOrganizacao'
CREATE INDEX [IX_FK_UsuarioOrganizacao]
ON [dbo].[Usuario]
    ([Organizacao_Id]);
GO

-- Creating foreign key on [AdminId] in table 'TermoUtilizacao'
ALTER TABLE [dbo].[TermoUtilizacao]
ADD CONSTRAINT [FK_AdminTermoUtilizacao]
    FOREIGN KEY ([AdminId])
    REFERENCES [dbo].[Admin]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AdminTermoUtilizacao'
CREATE INDEX [IX_FK_AdminTermoUtilizacao]
ON [dbo].[TermoUtilizacao]
    ([AdminId]);
GO

-- Creating foreign key on [AdminId] in table 'Faq'
ALTER TABLE [dbo].[Faq]
ADD CONSTRAINT [FK_AdminFaq]
    FOREIGN KEY ([AdminId])
    REFERENCES [dbo].[Admin]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AdminFaq'
CREATE INDEX [IX_FK_AdminFaq]
ON [dbo].[Faq]
    ([AdminId]);
GO

-- Creating foreign key on [CategoriaFaqId] in table 'Faq'
ALTER TABLE [dbo].[Faq]
ADD CONSTRAINT [FK_FaqCategoriaFaq]
    FOREIGN KEY ([CategoriaFaqId])
    REFERENCES [dbo].[CategoriaFaq]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FaqCategoriaFaq'
CREATE INDEX [IX_FK_FaqCategoriaFaq]
ON [dbo].[Faq]
    ([CategoriaFaqId]);
GO

-- Creating foreign key on [TipoTermoUtilizacaoId] in table 'TermoUtilizacao'
ALTER TABLE [dbo].[TermoUtilizacao]
ADD CONSTRAINT [FK_TermoUtilizacaoTipoTermoUtilizacao]
    FOREIGN KEY ([TipoTermoUtilizacaoId])
    REFERENCES [dbo].[TipoTermoUtilizacao]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TermoUtilizacaoTipoTermoUtilizacao'
CREATE INDEX [IX_FK_TermoUtilizacaoTipoTermoUtilizacao]
ON [dbo].[TermoUtilizacao]
    ([TipoTermoUtilizacaoId]);
GO

-- Creating foreign key on [AcaoHistoricoId] in table 'Historico'
ALTER TABLE [dbo].[Historico]
ADD CONSTRAINT [FK_HistoricoAcaoHistorico]
    FOREIGN KEY ([AcaoHistoricoId])
    REFERENCES [dbo].[AcaoHistorico]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_HistoricoAcaoHistorico'
CREATE INDEX [IX_FK_HistoricoAcaoHistorico]
ON [dbo].[Historico]
    ([AcaoHistoricoId]);
GO

-- Creating foreign key on [StatusId] in table 'Foto'
ALTER TABLE [dbo].[Foto]
ADD CONSTRAINT [FK_FotoStatus]
    FOREIGN KEY ([StatusId])
    REFERENCES [dbo].[Status]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FotoStatus'
CREATE INDEX [IX_FK_FotoStatus]
ON [dbo].[Foto]
    ([StatusId]);
GO

-- Creating foreign key on [AnimalId] in table 'Foto'
ALTER TABLE [dbo].[Foto]
ADD CONSTRAINT [FK_AnimalFoto]
    FOREIGN KEY ([AnimalId])
    REFERENCES [dbo].[Animal]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AnimalFoto'
CREATE INDEX [IX_FK_AnimalFoto]
ON [dbo].[Foto]
    ([AnimalId]);
GO

-- Creating foreign key on [RacaId] in table 'Animal'
ALTER TABLE [dbo].[Animal]
ADD CONSTRAINT [FK_AnimalRaca]
    FOREIGN KEY ([RacaId])
    REFERENCES [dbo].[Raca]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AnimalRaca'
CREATE INDEX [IX_FK_AnimalRaca]
ON [dbo].[Animal]
    ([RacaId]);
GO

-- Creating foreign key on [StatusId] in table 'Animal'
ALTER TABLE [dbo].[Animal]
ADD CONSTRAINT [FK_AnimalStatus]
    FOREIGN KEY ([StatusId])
    REFERENCES [dbo].[Status]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AnimalStatus'
CREATE INDEX [IX_FK_AnimalStatus]
ON [dbo].[Animal]
    ([StatusId]);
GO

-- Creating foreign key on [OrigemId] in table 'Animal'
ALTER TABLE [dbo].[Animal]
ADD CONSTRAINT [FK_AnimalOrigem]
    FOREIGN KEY ([OrigemId])
    REFERENCES [dbo].[Origem]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AnimalOrigem'
CREATE INDEX [IX_FK_AnimalOrigem]
ON [dbo].[Animal]
    ([OrigemId]);
GO

-- Creating foreign key on [CidadeId] in table 'Animal'
ALTER TABLE [dbo].[Animal]
ADD CONSTRAINT [FK_AnimalCidade]
    FOREIGN KEY ([CidadeId])
    REFERENCES [dbo].[Cidade]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AnimalCidade'
CREATE INDEX [IX_FK_AnimalCidade]
ON [dbo].[Animal]
    ([CidadeId]);
GO

-- Creating foreign key on [TamanhoId] in table 'Animal'
ALTER TABLE [dbo].[Animal]
ADD CONSTRAINT [FK_AnimalTamanho]
    FOREIGN KEY ([TamanhoId])
    REFERENCES [dbo].[Tamanho]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AnimalTamanho'
CREATE INDEX [IX_FK_AnimalTamanho]
ON [dbo].[Animal]
    ([TamanhoId]);
GO

-- Creating foreign key on [AnimalCor_Cor_Id] in table 'AnimalCor'
ALTER TABLE [dbo].[AnimalCor]
ADD CONSTRAINT [FK_AnimalCor_Animal]
    FOREIGN KEY ([AnimalCor_Cor_Id])
    REFERENCES [dbo].[Animal]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Cor_Id] in table 'AnimalCor'
ALTER TABLE [dbo].[AnimalCor]
ADD CONSTRAINT [FK_AnimalCor_Cor]
    FOREIGN KEY ([Cor_Id])
    REFERENCES [dbo].[Cor]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AnimalCor_Cor'
CREATE INDEX [IX_FK_AnimalCor_Cor]
ON [dbo].[AnimalCor]
    ([Cor_Id]);
GO

-- Creating foreign key on [TemperamentoId] in table 'Animal'
ALTER TABLE [dbo].[Animal]
ADD CONSTRAINT [FK_AnimalTemperamento]
    FOREIGN KEY ([TemperamentoId])
    REFERENCES [dbo].[Temperamento]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AnimalTemperamento'
CREATE INDEX [IX_FK_AnimalTemperamento]
ON [dbo].[Animal]
    ([TemperamentoId]);
GO

-- Creating foreign key on [TipoAnimalId] in table 'Raca'
ALTER TABLE [dbo].[Raca]
ADD CONSTRAINT [FK_RacaTipoAnimal]
    FOREIGN KEY ([TipoAnimalId])
    REFERENCES [dbo].[TipoAnimal]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RacaTipoAnimal'
CREATE INDEX [IX_FK_RacaTipoAnimal]
ON [dbo].[Raca]
    ([TipoAnimalId]);
GO

-- Creating foreign key on [EstadoId] in table 'Cidade'
ALTER TABLE [dbo].[Cidade]
ADD CONSTRAINT [FK_CidadeEstado]
    FOREIGN KEY ([EstadoId])
    REFERENCES [dbo].[Estado]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CidadeEstado'
CREATE INDEX [IX_FK_CidadeEstado]
ON [dbo].[Cidade]
    ([EstadoId]);
GO

-- Creating foreign key on [TipoContatoId] in table 'Contato'
ALTER TABLE [dbo].[Contato]
ADD CONSTRAINT [FK_ContatoTipoContato]
    FOREIGN KEY ([TipoContatoId])
    REFERENCES [dbo].[TipoContato]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ContatoTipoContato'
CREATE INDEX [IX_FK_ContatoTipoContato]
ON [dbo].[Contato]
    ([TipoContatoId]);
GO

-- Creating foreign key on [MotivoDenunciaId] in table 'Denuncia'
ALTER TABLE [dbo].[Denuncia]
ADD CONSTRAINT [FK_DenunciaMotivoDenuncia]
    FOREIGN KEY ([MotivoDenunciaId])
    REFERENCES [dbo].[MotivoDenuncia]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DenunciaMotivoDenuncia'
CREATE INDEX [IX_FK_DenunciaMotivoDenuncia]
ON [dbo].[Denuncia]
    ([MotivoDenunciaId]);
GO

-- Creating foreign key on [TipoNotificacaoId] in table 'Notificacao'
ALTER TABLE [dbo].[Notificacao]
ADD CONSTRAINT [FK_NotificacaoTipoNotificacao]
    FOREIGN KEY ([TipoNotificacaoId])
    REFERENCES [dbo].[TipoNotificacao]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_NotificacaoTipoNotificacao'
CREATE INDEX [IX_FK_NotificacaoTipoNotificacao]
ON [dbo].[Notificacao]
    ([TipoNotificacaoId]);
GO

-- Creating foreign key on [UsuarioId] in table 'Notificacao'
ALTER TABLE [dbo].[Notificacao]
ADD CONSTRAINT [FK_UsuarioNotificacao]
    FOREIGN KEY ([UsuarioId])
    REFERENCES [dbo].[Usuario]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuarioNotificacao'
CREATE INDEX [IX_FK_UsuarioNotificacao]
ON [dbo].[Notificacao]
    ([UsuarioId]);
GO

-- Creating foreign key on [UsuarioId] in table 'ChaveAcesso'
ALTER TABLE [dbo].[ChaveAcesso]
ADD CONSTRAINT [FK_UsuarioChaveAcesso]
    FOREIGN KEY ([UsuarioId])
    REFERENCES [dbo].[Usuario]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuarioChaveAcesso'
CREATE INDEX [IX_FK_UsuarioChaveAcesso]
ON [dbo].[ChaveAcesso]
    ([UsuarioId]);
GO

-- Creating foreign key on [TipoChave_Id] in table 'ChaveAcesso'
ALTER TABLE [dbo].[ChaveAcesso]
ADD CONSTRAINT [FK_ChaveAcessoTipoChave]
    FOREIGN KEY ([TipoChave_Id])
    REFERENCES [dbo].[TipoChave]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ChaveAcessoTipoChave'
CREATE INDEX [IX_FK_ChaveAcessoTipoChave]
ON [dbo].[ChaveAcesso]
    ([TipoChave_Id]);
GO

-- Creating foreign key on [TipoNotificacao_Id] in table 'TipoNotificacaoMeioNotificacao'
ALTER TABLE [dbo].[TipoNotificacaoMeioNotificacao]
ADD CONSTRAINT [FK_TipoNotificacaoMeioNotificacao_TipoNotificacao]
    FOREIGN KEY ([TipoNotificacao_Id])
    REFERENCES [dbo].[TipoNotificacao]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [MeioNotificacao_Id] in table 'TipoNotificacaoMeioNotificacao'
ALTER TABLE [dbo].[TipoNotificacaoMeioNotificacao]
ADD CONSTRAINT [FK_TipoNotificacaoMeioNotificacao_MeioNotificacao]
    FOREIGN KEY ([MeioNotificacao_Id])
    REFERENCES [dbo].[MeioNotificacao]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TipoNotificacaoMeioNotificacao_MeioNotificacao'
CREATE INDEX [IX_FK_TipoNotificacaoMeioNotificacao_MeioNotificacao]
ON [dbo].[TipoNotificacaoMeioNotificacao]
    ([MeioNotificacao_Id]);
GO

-- Creating foreign key on [AnimalId] in table 'Doacao'
ALTER TABLE [dbo].[Doacao]
ADD CONSTRAINT [FK_AnimalDoacao]
    FOREIGN KEY ([AnimalId])
    REFERENCES [dbo].[Animal]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AnimalDoacao'
CREATE INDEX [IX_FK_AnimalDoacao]
ON [dbo].[Doacao]
    ([AnimalId]);
GO

-- Creating foreign key on [DoacaoId] in table 'Candidato'
ALTER TABLE [dbo].[Candidato]
ADD CONSTRAINT [FK_DoacaoCandidato]
    FOREIGN KEY ([DoacaoId])
    REFERENCES [dbo].[Doacao]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DoacaoCandidato'
CREATE INDEX [IX_FK_DoacaoCandidato]
ON [dbo].[Candidato]
    ([DoacaoId]);
GO

-- Creating foreign key on [FormularioId] in table 'Contato'
ALTER TABLE [dbo].[Contato]
ADD CONSTRAINT [FK_FormularioContato]
    FOREIGN KEY ([FormularioId])
    REFERENCES [dbo].[Formulario]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FormularioContato'
CREATE INDEX [IX_FK_FormularioContato]
ON [dbo].[Contato]
    ([FormularioId]);
GO

-- Creating foreign key on [TipoResidenciaId] in table 'Formulario'
ALTER TABLE [dbo].[Formulario]
ADD CONSTRAINT [FK_FormularioTipoResidencia]
    FOREIGN KEY ([TipoResidenciaId])
    REFERENCES [dbo].[TipoResidencia]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FormularioTipoResidencia'
CREATE INDEX [IX_FK_FormularioTipoResidencia]
ON [dbo].[Formulario]
    ([TipoResidenciaId]);
GO

-- Creating foreign key on [UsuarioId] in table 'Formulario'
ALTER TABLE [dbo].[Formulario]
ADD CONSTRAINT [FK_UsuarioFormulario]
    FOREIGN KEY ([UsuarioId])
    REFERENCES [dbo].[Usuario]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuarioFormulario'
CREATE INDEX [IX_FK_UsuarioFormulario]
ON [dbo].[Formulario]
    ([UsuarioId]);
GO

-- Creating foreign key on [Status_Id] in table 'Formulario'
ALTER TABLE [dbo].[Formulario]
ADD CONSTRAINT [FK_FormularioStatus]
    FOREIGN KEY ([Status_Id])
    REFERENCES [dbo].[Status]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FormularioStatus'
CREATE INDEX [IX_FK_FormularioStatus]
ON [dbo].[Formulario]
    ([Status_Id]);
GO

-- Creating foreign key on [CidadeId] in table 'Formulario'
ALTER TABLE [dbo].[Formulario]
ADD CONSTRAINT [FK_FormularioCidade]
    FOREIGN KEY ([CidadeId])
    REFERENCES [dbo].[Cidade]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FormularioCidade'
CREATE INDEX [IX_FK_FormularioCidade]
ON [dbo].[Formulario]
    ([CidadeId]);
GO

-- Creating foreign key on [FormularioId] in table 'Candidato'
ALTER TABLE [dbo].[Candidato]
ADD CONSTRAINT [FK_CandidatoFormulario]
    FOREIGN KEY ([FormularioId])
    REFERENCES [dbo].[Formulario]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CandidatoFormulario'
CREATE INDEX [IX_FK_CandidatoFormulario]
ON [dbo].[Candidato]
    ([FormularioId]);
GO

-- Creating foreign key on [Status_Id] in table 'Candidato'
ALTER TABLE [dbo].[Candidato]
ADD CONSTRAINT [FK_CandidatoStatus]
    FOREIGN KEY ([Status_Id])
    REFERENCES [dbo].[Status]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CandidatoStatus'
CREATE INDEX [IX_FK_CandidatoStatus]
ON [dbo].[Candidato]
    ([Status_Id]);
GO

-- Creating foreign key on [UsuarioId] in table 'RelacaoUsuarioAnimal'
ALTER TABLE [dbo].[RelacaoUsuarioAnimal]
ADD CONSTRAINT [FK_UsuarioRelacaoUsuarioAnimal]
    FOREIGN KEY ([UsuarioId])
    REFERENCES [dbo].[Usuario]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuarioRelacaoUsuarioAnimal'
CREATE INDEX [IX_FK_UsuarioRelacaoUsuarioAnimal]
ON [dbo].[RelacaoUsuarioAnimal]
    ([UsuarioId]);
GO

-- Creating foreign key on [AnimalId] in table 'RelacaoUsuarioAnimal'
ALTER TABLE [dbo].[RelacaoUsuarioAnimal]
ADD CONSTRAINT [FK_AnimalRelacaoUsuarioAnimal]
    FOREIGN KEY ([AnimalId])
    REFERENCES [dbo].[Animal]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AnimalRelacaoUsuarioAnimal'
CREATE INDEX [IX_FK_AnimalRelacaoUsuarioAnimal]
ON [dbo].[RelacaoUsuarioAnimal]
    ([AnimalId]);
GO

-- Creating foreign key on [StatusId] in table 'RelacaoUsuarioAnimal'
ALTER TABLE [dbo].[RelacaoUsuarioAnimal]
ADD CONSTRAINT [FK_RelacaoUsuarioAnimalStatus]
    FOREIGN KEY ([StatusId])
    REFERENCES [dbo].[Status]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RelacaoUsuarioAnimalStatus'
CREATE INDEX [IX_FK_RelacaoUsuarioAnimalStatus]
ON [dbo].[RelacaoUsuarioAnimal]
    ([StatusId]);
GO

-- Creating foreign key on [AdminId] in table 'Denuncia'
ALTER TABLE [dbo].[Denuncia]
ADD CONSTRAINT [FK_AdminDenuncia]
    FOREIGN KEY ([AdminId])
    REFERENCES [dbo].[Admin]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AdminDenuncia'
CREATE INDEX [IX_FK_AdminDenuncia]
ON [dbo].[Denuncia]
    ([AdminId]);
GO

-- Creating foreign key on [Ticket_Id] in table 'Denuncia'
ALTER TABLE [dbo].[Denuncia]
ADD CONSTRAINT [FK_DenunciaTicket]
    FOREIGN KEY ([Ticket_Id])
    REFERENCES [dbo].[Ticket]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DenunciaTicket'
CREATE INDEX [IX_FK_DenunciaTicket]
ON [dbo].[Denuncia]
    ([Ticket_Id]);
GO

-- Creating foreign key on [TipoTicketId] in table 'Ticket'
ALTER TABLE [dbo].[Ticket]
ADD CONSTRAINT [FK_TicketTipoTicket]
    FOREIGN KEY ([TipoTicketId])
    REFERENCES [dbo].[TipoTicket]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TicketTipoTicket'
CREATE INDEX [IX_FK_TicketTipoTicket]
ON [dbo].[Ticket]
    ([TipoTicketId]);
GO

-- Creating foreign key on [TipoObjetoId] in table 'Objeto'
ALTER TABLE [dbo].[Objeto]
ADD CONSTRAINT [FK_ObjetoTipoObjeto]
    FOREIGN KEY ([TipoObjetoId])
    REFERENCES [dbo].[TipoObjeto]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ObjetoTipoObjeto'
CREATE INDEX [IX_FK_ObjetoTipoObjeto]
ON [dbo].[Objeto]
    ([TipoObjetoId]);
GO

-- Creating foreign key on [ObjetoId] in table 'MotivoDenuncia'
ALTER TABLE [dbo].[MotivoDenuncia]
ADD CONSTRAINT [FK_ObjetoMotivoDenuncia]
    FOREIGN KEY ([ObjetoId])
    REFERENCES [dbo].[Objeto]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ObjetoMotivoDenuncia'
CREATE INDEX [IX_FK_ObjetoMotivoDenuncia]
ON [dbo].[MotivoDenuncia]
    ([ObjetoId]);
GO

-- Creating foreign key on [ObjetoId] in table 'TipoTicket'
ALTER TABLE [dbo].[TipoTicket]
ADD CONSTRAINT [FK_TipoTicketObjeto]
    FOREIGN KEY ([ObjetoId])
    REFERENCES [dbo].[Objeto]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TipoTicketObjeto'
CREATE INDEX [IX_FK_TipoTicketObjeto]
ON [dbo].[TipoTicket]
    ([ObjetoId]);
GO

-- Creating foreign key on [UsuarioId] in table 'Apreciar'
ALTER TABLE [dbo].[Apreciar]
ADD CONSTRAINT [FK_UsuarioApreciar]
    FOREIGN KEY ([UsuarioId])
    REFERENCES [dbo].[Usuario]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuarioApreciar'
CREATE INDEX [IX_FK_UsuarioApreciar]
ON [dbo].[Apreciar]
    ([UsuarioId]);
GO

-- Creating foreign key on [ObjetoId] in table 'Apreciar'
ALTER TABLE [dbo].[Apreciar]
ADD CONSTRAINT [FK_ApreciarObjeto]
    FOREIGN KEY ([ObjetoId])
    REFERENCES [dbo].[Objeto]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ApreciarObjeto'
CREATE INDEX [IX_FK_ApreciarObjeto]
ON [dbo].[Apreciar]
    ([ObjetoId]);
GO

-- Creating foreign key on [UsuarioId] in table 'Seguir'
ALTER TABLE [dbo].[Seguir]
ADD CONSTRAINT [FK_UsuarioSeguir]
    FOREIGN KEY ([UsuarioId])
    REFERENCES [dbo].[Usuario]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuarioSeguir'
CREATE INDEX [IX_FK_UsuarioSeguir]
ON [dbo].[Seguir]
    ([UsuarioId]);
GO

-- Creating foreign key on [UsuarioIdRemetente] in table 'Mensagem'
ALTER TABLE [dbo].[Mensagem]
ADD CONSTRAINT [FK_UsuarioMensagemDestinatario]
    FOREIGN KEY ([UsuarioIdRemetente])
    REFERENCES [dbo].[Usuario]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuarioMensagemDestinatario'
CREATE INDEX [IX_FK_UsuarioMensagemDestinatario]
ON [dbo].[Mensagem]
    ([UsuarioIdRemetente]);
GO

-- Creating foreign key on [UsuarioIdDestinatario] in table 'Mensagem'
ALTER TABLE [dbo].[Mensagem]
ADD CONSTRAINT [FK_UsuarioMensagemRemetente]
    FOREIGN KEY ([UsuarioIdDestinatario])
    REFERENCES [dbo].[Usuario]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuarioMensagemRemetente'
CREATE INDEX [IX_FK_UsuarioMensagemRemetente]
ON [dbo].[Mensagem]
    ([UsuarioIdDestinatario]);
GO

-- Creating foreign key on [DoacaoId] in table 'Mensagem'
ALTER TABLE [dbo].[Mensagem]
ADD CONSTRAINT [FK_DoacaoMensagem]
    FOREIGN KEY ([DoacaoId])
    REFERENCES [dbo].[Doacao]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DoacaoMensagem'
CREATE INDEX [IX_FK_DoacaoMensagem]
ON [dbo].[Mensagem]
    ([DoacaoId]);
GO

-- Creating foreign key on [UsuarioId] in table 'Doacao'
ALTER TABLE [dbo].[Doacao]
ADD CONSTRAINT [FK_DoacaoUsuario]
    FOREIGN KEY ([UsuarioId])
    REFERENCES [dbo].[Usuario]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DoacaoUsuario'
CREATE INDEX [IX_FK_DoacaoUsuario]
ON [dbo].[Doacao]
    ([UsuarioId]);
GO

-- Creating foreign key on [StatusId] in table 'Denuncia'
ALTER TABLE [dbo].[Denuncia]
ADD CONSTRAINT [FK_DenunciaStatus]
    FOREIGN KEY ([StatusId])
    REFERENCES [dbo].[Status]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DenunciaStatus'
CREATE INDEX [IX_FK_DenunciaStatus]
ON [dbo].[Denuncia]
    ([StatusId]);
GO

-- Creating foreign key on [StatusId] in table 'Admin'
ALTER TABLE [dbo].[Admin]
ADD CONSTRAINT [FK_AdminStatus]
    FOREIGN KEY ([StatusId])
    REFERENCES [dbo].[Status]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AdminStatus'
CREATE INDEX [IX_FK_AdminStatus]
ON [dbo].[Admin]
    ([StatusId]);
GO

-- Creating foreign key on [Admin_Id] in table 'Ticket'
ALTER TABLE [dbo].[Ticket]
ADD CONSTRAINT [FK_TicketAdmin]
    FOREIGN KEY ([Admin_Id])
    REFERENCES [dbo].[Admin]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TicketAdmin'
CREATE INDEX [IX_FK_TicketAdmin]
ON [dbo].[Ticket]
    ([Admin_Id]);
GO

-- Creating foreign key on [AnimalId] in table 'Seguir'
ALTER TABLE [dbo].[Seguir]
ADD CONSTRAINT [FK_SeguirAnimal]
    FOREIGN KEY ([AnimalId])
    REFERENCES [dbo].[Animal]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SeguirAnimal'
CREATE INDEX [IX_FK_SeguirAnimal]
ON [dbo].[Seguir]
    ([AnimalId]);
GO

-- Creating foreign key on [ObjetoId] in table 'AcaoHistorico'
ALTER TABLE [dbo].[AcaoHistorico]
ADD CONSTRAINT [FK_AcaoHistoricoObjeto]
    FOREIGN KEY ([ObjetoId])
    REFERENCES [dbo].[Objeto]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AcaoHistoricoObjeto'
CREATE INDEX [IX_FK_AcaoHistoricoObjeto]
ON [dbo].[AcaoHistorico]
    ([ObjetoId]);
GO

-- Creating foreign key on [EstadoCivilId] in table 'Formulario'
ALTER TABLE [dbo].[Formulario]
ADD CONSTRAINT [FK_FormularioEstadoCivil]
    FOREIGN KEY ([EstadoCivilId])
    REFERENCES [dbo].[EstadoCivil]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FormularioEstadoCivil'
CREATE INDEX [IX_FK_FormularioEstadoCivil]
ON [dbo].[Formulario]
    ([EstadoCivilId]);
GO

-- Creating foreign key on [AdminId1] in table 'Permissao'
ALTER TABLE [dbo].[Permissao]
ADD CONSTRAINT [FK_AdminPermissao]
    FOREIGN KEY ([AdminId1])
    REFERENCES [dbo].[Admin]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AdminPermissao'
CREATE INDEX [IX_FK_AdminPermissao]
ON [dbo].[Permissao]
    ([AdminId1]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------